<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/customer/customer" data-pjax><i class="ti-angle-left"></i> 返回</a>
        <button class="btn btn-primary navbar-btn" onclick="crawl()"><i class="ti-plus"></i> 链接导入</button>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/customer/customer/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="companyName" class="col-sm-2 control-label">公司名称</label>
                            <div class="col-sm-8">
                            <input type="text" id="companyName" class="form-control" name="companyName" data-parsley-required="true" data-parsley-maxlength="200" placeholder="公司名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="level" class="col-sm-2 control-label">等级</label>
                            <div class="col-sm-8">
                                <select id="level" class="form-control" name="level" data-parsley-required="true">
                                    <option value="A级">A级</option>
                                    <option value="B级">B级</option>
                                    <option value="E级">C级</option>
                                    <option value="D级">D级</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="telphone" class="col-sm-2 control-label">联系电话</label>
                            <div class="col-sm-8">
                            <input type="text" id="telphone" class="form-control" name="telphone" data-parsley-required="true" placeholder="联系电话" data-parsley-maxlength="30">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="telphone" class="col-sm-2 control-label">手机号码</label>
                            <div class="col-sm-8">
                                <input type="text" id="mobile" class="form-control" name="mobile"  placeholder="手机号码" data-parsley-maxlength="11">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">地址</label>
                            <div class="col-sm-8">
                            <input type="text" id="address" class="form-control" name="address" data-parsley-required="false" data-parsley-maxlength="250" placeholder="地址">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="website" class="col-sm-2 control-label">公司网址</label>
                                <div class="col-sm-8">
                                    <input type="text" id="website" class="form-control" name="website" data-parsley-required="true"  data-parsley-maxlength="1000" placeholder="公司网址">
                                </div>
                        </div>
                        <div class="form-group">
                            <label for="keyword" class="col-sm-2 control-label">关键词</label>
                            <div class="col-sm-8">
                            <input type="text" id="keyword" class="form-control" name="keyword" data-parsley-required="false" placeholder="关键词">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="contactsName" class="col-sm-2 control-label">联系人</label>
                            <div class="col-sm-8">
                            <input type="text" id="contactsName" class="form-control" name="contactsName" data-parsley-required="true" data-parsley-maxlength="30" placeholder="联系人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="mainBusiness" class="col-sm-2 control-label">主营业务</label>
                            <div class="col-sm-8">
                            <input type="text" id="mainBusiness" class="form-control" name="mainBusiness" data-parsley-required="false" data-parsley-maxlength="250" placeholder="主营业务">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<div id="dialogCrawl" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">爬取</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <input type="text" id="url" class="form-control" name="url"  placeholder="请输入链接">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取  消</button>
                <button id="okCrawl" type="button" class="btn btn-primary" data-loading-text="正在爬取...">爬取</button>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">
    $(document).ready(function () {
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    form.resetForm();
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
    function crawl() {
        var dialog = $("#dialogCrawl");
        dialog.modal("show");
        dialog.find("#okCrawl").unbind("click");
        dialog.find("#okCrawl").bind("click", function (event) {
            var url=$("#url").val();
            var btn = $(this);
            btn.button("loading");
            $.post("${base}/platform/customer/customer/crawl?url=" + url, {}, function (data) {
                if (data.code == 1) {
                    Toast.error(data.msg);
                } else {
                    $('#addForm').resetForm();
                    $("#companyName").val(data.companyName);
                    $("#telphone").val(data.telphone);
                    $("#website").val(data.website);
                    $("#contactsName").val(data.contactsName);
                    $("#address").val(data.address);
                    $("#mobile").val(data.mobile);
                    $("#level option").each(function () {
                        if($(this).val()==data.level){
                            $(this).attr("selected",true);
                            return;
                        }
                    })
                }
                //重置按钮状态，关闭提示框
                btn.button("reset");
                dialog.modal("hide");
            }, "json");
        });
    }

</script>
<%}%>


